<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class log_db 
	{
		public function Them($MaNguoiDung, $ThoiGian)
		{
			$sql = "INSERT INTO `tbl_log`(`MaNguoiDung`, `ThoiGian`)
					VALUES ('$MaNguoiDung', '$ThoiGian')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaNguoiDung)
		{
			$sql = "DELETE FROM `tbl_log` WHERE `MaNguoiDung` = '$MaNguoiDung'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaNguoiDung, $ThoiGian)
		{
			$sql = "UPDATE `tbl_log`
					SET `ThoiGian` = '$ThoiGian'
					WHERE `MaNguoiDung` = '$MaNguoiDung'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaNguoiDung, $ThoiGian)
		{
			$sql = "SELECT * FROM `tbl_log` WHERE 1  ";
			if($MaNguoiDung != "")
				$sql .= " AND `MaNguoiDung` = '$MaNguoiDung' ";

			if($ThoiGian != "0000-00-00 00:00:00")
				$sql .= " AND `ThoiGian` = '$ThoiGian' ";
			$sql .= " ORDER BY `ThoiGian` DESC ";
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		
		public function LayDanhSachPaging($MaNguoiDung, $ThoiGian, $Start, $Limit)
		{
			$sql = "SELECT * FROM `tbl_log` WHERE 1  ";
			if($MaNguoiDung != "")
				$sql .= " AND `MaNguoiDung` = '$MaNguoiDung' ";

			if($ThoiGian != "0000-00-00 00:00:00")
				$sql .= " AND `ThoiGian` = '$ThoiGian' ";
			$sql .= " ORDER BY `ThoiGian` DESC LIMIT $Start, $Limit ";
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		
	}

